import 'dart:ui';

import 'package:flutter/material.dart';

enum CommentColor{
  read("红色",Colors.red),
  yellow("黄色",Colors.yellow),
  blue("蓝色",Colors.blue),
  green("绿色",Colors.green),
  grey("灰色",Colors.grey),
  brown("棕色",Colors.brown),
  pink("粉色",Colors.pink),
  white("白色",Colors.white),
  black("黑色",Colors.black),
  purple("紫色",Colors.purple),
  orange("橙色",Colors.orange)
  ;

  final String title;
  final Color value;
  const CommentColor(this.title,this.value);
  
  static Color getValueByTitle(String s) {
    return values.firstWhere((test) => test.title == s ).value;
  }
}
/**
 * *色 字体颜色
 * *号 字号
 * 加粗 倾斜 下划线 删除线 
 */
class CommentParser{
  static TextStyle getTextStyle(String comment) {
      var se = RegExp(r'\S+色').firstMatch(comment);
      var ti = RegExp(r'(\S+)号').firstMatch(comment);
      var size;
      var color;
      if(ti !=null && ti.groupCount > 0){
          size = double.parse(ti.group(1).toString());
      }
      if(se !=null){
        color = CommentColor.getValueByTitle(se.input);
      }
      var rt = TextStyle(
          fontSize: size,
          color: color,
          fontWeight: comment.contains("加粗") ? FontWeight.bold:null,
          fontStyle: comment.contains("倾斜") ? FontStyle.italic : null,
          decoration: comment.contains("线") ?  TextDecoration.combine([
            if(comment.contains("下划线")) TextDecoration.underline, // 下划线
            if(comment.contains("删除线")) TextDecoration.lineThrough
          ]) : null,
      );
      
      return rt;
  }
}